package org.graduation.model.common;


import java.io.Serializable;
import java.util.Objects;

public class ResponseResult<T> implements Serializable {
    int code = 200;
    String msg = "成功";
    T data;

    public ResponseResult() {
    }

    public ResponseResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        if (!Objects.isNull(data)) {
            this.data = data;
        }
    }

    public static <T> ResponseResult<T> success(String msg, T data) {
        return new ResponseResult<T>(200, msg, data);
    }

    public static <T> ResponseResult<T> success(T data) {
        return success("成功", data);
    }

    public static ResponseResult success() {
        return success("");
    }

    public static ResponseResult failed(String msg, Object data) {
        return new ResponseResult(-1, msg, data);
    }

    public static ResponseResult failed(String msg) {
        return failed(msg, "");
    }

    public static ResponseResult failed() {
        return failed("服务错误，请稍候再试");
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }
}